package com.elinkway.infinitemovies.bigdata;

import android.os.Bundle;

import com.apkfuns.logutils.LogUtils;

import java.util.HashMap;
import java.util.Map;

public abstract class BigDataBaseTask implements Runnable {

    public boolean isCompelete = false;
    public int retryTime = 0;
    protected Bundle params = new Bundle();
    private Map<String, String> mMap;
    private boolean isBigData = true;

    public boolean isBigData() {
        return isBigData;
    }

    public void setBigData(boolean bigData) {
        isBigData = bigData;
    }

    public void putParam(String key, String value) {
        try {
            params.putString(key, value);
        } catch (Exception e) {
            LogUtils.e("BigDataTask put param error:" + e.getMessage());
        }
    }

    public void putOneBundle(Bundle extraParams){
        params.putAll(extraParams);
    }

    public void setMap(Map<String, String> map) {
        mMap = map;
    }

    public Map<String, String> getParamMap() {
        return mMap == null ? new HashMap<String, String>() : mMap;
    }

    public String getParam(String key) {
        return getParam(key, null);
    }

    public String getParam(String key, String fallback) {
        String ret = params.getString(key);
        return ret == null ? "" : ret;
    }

    public abstract boolean execute();

    @Override
    public final void run() {
        //暂时去除大数据部分的上报
        if(isBigData){
            isCompelete = true;
        }else{
            isCompelete = execute();
        }

    }
}
